package com.zh.work.service.platform.channel.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zh.work.dao.platform.channel.ChannelLogMapper;
import com.zh.work.dao.platform.channel.TongLianLogMapper;
import com.zh.work.entity.StatisticalEntity;
import com.zh.work.entity.channel.ChannelLogEntity;
import com.zh.work.entity.channel.TongLianLogEntity;
import com.zh.work.service.platform.channel.ChannelLogService;
import com.zh.work.service.platform.channel.TongLianLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @version 1.0
 * @Description :  通联进件日志业务实现类
 * @Author : chenfei
 * @Create in : 2020/10/29 17:35
 */
@Service
public class TongLianLogImpl extends ServiceImpl<TongLianLogMapper, TongLianLogEntity> implements TongLianLogService {

    @Autowired
    private TongLianLogMapper dao;

    @Override
    public List<TongLianLogEntity> getPage(String addStartTime, String addEndTime, Page<TongLianLogEntity> page, TongLianLogEntity param) {
        Map<String ,Object> params = new HashMap<>();
        params.put("method",param.getMethod());
        params.put("result",param.getResult());
        params.put("params",param.getParams());
        params.put("addStartTime",addStartTime);
        params.put("addEndTime",addEndTime);
        params.put("current",(page.getCurrent() - 1) * page.getSize());
        params.put("size",page.getSize());
        return dao.getPage(params);
    }

    @Override
    public Long getPageCount(String addStartTime, String addEndTime,  Page<TongLianLogEntity> page, TongLianLogEntity param) {
        Map<String ,Object> params = new HashMap<>();
        params.put("method",param.getMethod());
        params.put("result",param.getResult());
        params.put("params",param.getParams());
        params.put("addStartTime",addStartTime);
        params.put("addEndTime",addEndTime);
        return   dao.getPageCount(params);
    }

    @Override
    public List<TongLianLogEntity> getTongLianLogDownload(String addStartTime, String addEndTime, TongLianLogEntity param) {
        Map<String ,Object> params = new HashMap<>();
        params.put("method",param.getMethod());
        params.put("result",param.getResult());
        params.put("params",param.getParams());
        params.put("addStartTime",addStartTime);
        params.put("addEndTime",addEndTime);
        return  dao.getTongLianLogDownload(params);
    }

    @Override
    public List<StatisticalEntity> getStatisticalTongLianLog() {
        List<StatisticalEntity> data = dao.getStatisticalSu();
        data.stream().forEach(Value->Value.setType("成功"));
        List<StatisticalEntity> failData = dao.getStatisticalFail();
        failData.stream().forEach(Value->Value.setType("失败"));
        failData.stream().forEach(Value->data.add(Value));
        return data;
    }


}
